package
{
	import event.UIEditsEventName;
	
	import fl.controls.ScrollBarDirection;
	import fl.controls.ScrollPolicy;
	import fl.controls.TileList;
	import fl.data.DataProvider;
	import fl.events.ListEvent;
	
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import kingsAsLib.events.EventManager;
	import kingsAsLib.events.KEvents;


	/**
	 * @author kings
	 * @E-mail: qywangweiqiang@126.com
	 * 2012-11-29上午12:42:08
	 * */
	public class ClassLibUI extends Sprite
	{
		static private var classLibUI:ClassLibUI=new ClassLibUI();
		private var classList:TileList;

		public function ClassLibUI()
		{

//			var textLabel:TextField=new TextField();
//			textLabel.text="类名";
//			addChild(textLabel);

			classList=new TileList();
		
			classList.columnWidth=170;
			classList.rowHeight=24;
			classList.columnCount=1;
			classList.rowCount=20;
			classList.direction=ScrollBarDirection.VERTICAL;
			classList.verticalScrollPolicy=ScrollPolicy.OFF
			classList.move(0, 0);
			addChild(classList);


			initClassList(LoadFileList.getInstance().classArr);
		}

		static public function instance():ClassLibUI
		{
			return classLibUI;
		}

		private function initClassList(classArr:Vector.<String>):void
		{
			var sp:Sprite=new Sprite();
			var dp:DataProvider=new DataProvider();

			for (var i:int=0; i < classArr.length; i++)
			{
				dp.addItem({label:classArr[i]});
			}


			classList.dataProvider=dp;

			classList.addEventListener(fl.events.ListEvent.ITEM_CLICK, classItemClickHandle);
		}


		protected function classItemClickHandle(e:ListEvent):void
		{

			var item:Object=e.item;
			var className:String=item.label;

			if (className == null)
			{
				return;
			}

			EventManager.dispatchEvent(new KEvents(UIEditsEventName.classItemClick, className));

		}
	}

	//end class
}
